package com.carkeeper.serve.controller;


import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.pojo.KnowledgeBaseInfo;
import com.carkeeper.serve.service.KnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/esKnowledge")
public class EsKnowledgeController {


    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;


    @Autowired
    private KnowledgeService knowledgeService;

    /**
     * 创建索引库
     */
    @GetMapping("/createES")
    public Result createElasticsearch() {
        //创建索引
        elasticsearchTemplate.createIndex(KnowledgeBaseInfo.class);
        //创建映射
        elasticsearchTemplate.putMapping(KnowledgeBaseInfo.class);
        //返回结果
        return new Result(true, StatusCode.OK, "创建索引库成功！");
    }


    /**
     * 批量导入
     * @return
     */
    @PostMapping("/batchSingleAddES")
    public Result batchSingleAddES() {
        return knowledgeService.batchSingleAddES();
    }



    /**
     * 添加推文
     * @param knowledgeBaseInfo
     * @return
     */
    @PostMapping("/knowledgeBaseInfo")
    public Result addKnowledgeBaseInfo(KnowledgeBaseInfo knowledgeBaseInfo) {
        return null;
    }
}
